#pragma warning disable 1591
#if SERVER
using System;
using System.Collections.Generic;
using System.Text;
using Saltarelle;

namespace DemoWeb {
	public partial class DragDropTestControl : IControl {
		private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();

		private Position position = PositionHelper.NotPositioned;
		public Position Position { get { return position; } set { position = value; } }

		private string id;
		public string Id {
			get { return id; }
			set {
				foreach (KeyValuePair<string, IControl> kvp in controls)
					kvp.Value.Id = value + "_" + kvp.Key;
				this.id = value;
			}
		}

		public object ConfigObject {
			get {
				Dictionary<string, object> __cfg = new Dictionary<string, object>();
				__cfg["id"] = id;
				__cfg["numItems"] = this.numItems;
				return __cfg;
			}
		}

		private string GetHtml() {
			StringBuilder sb = new StringBuilder();
			sb.Append(@" <div class=""DragDropTestControl"" style=""width: 300px; height: 300px; overflow: auto; border: solid 1px black; position: relative;");
			sb.Append(PositionHelper.CreateStyle(Position, -1, -1));
			sb.Append(@""" id=""");
			sb.Append(Id);
			sb.Append(@"""> <div style=""width: 400px""> ");
			for (int i = 0; i < numItems; i++) {
				sb.Append(@" <div style=""width: 50px; height: 50px; margin: 10px; float: left; border: solid 1px black; background-color: white""> ");
				sb.Append("Item " + i.ToString());
				sb.Append(@" </div> ");
			}
			sb.Append(@" </div> </div>");
			return sb.ToString();
		}

		private int numItems;

		public string Html {
			get {
				if (string.IsNullOrEmpty(id))
					throw new InvalidOperationException("Must assign Id before rendering.");
				return GetHtml();
			}
		}

		public DragDropTestControl() {
			IScriptManagerServiceExtensions.RegisterClientType(GlobalServices.GetService<IScriptManagerService>(), GetType());
			Constructed();
		}
	}
}
#endif
#if CLIENT
using System;
using System.DHTML;
using Saltarelle;

namespace DemoWeb {
	public partial class DragDropTestControl : IControl, Saltarelle.UI.IDragSource, Saltarelle.UI.IDropTarget {
		private Dictionary controls = new Dictionary();

		private Position position;
		public Position Position {
			get { return isAttached ? PositionHelper.GetPosition(GetElement()) : position; }
			set {
				position = value;
				if (isAttached)
					PositionHelper.ApplyPosition(GetElement(), value);
			}
		}

		private bool isAttached = false;
		public DOMElement GetElement() { return isAttached ? Document.GetElementById(id) : null; }

		private string id;
		public string Id {
			get { return id; }
			set {
				foreach (DictionaryEntry kvp in controls)
					((IControl)kvp.Value).Id = value + "_" + kvp.Key;
				if (isAttached)
					GetElement().ID = value;
				this.id = value;
			}
		}

		private int numItems;

		private void AttachSelf() {
			this.isAttached = true;
			Attached();
		}

		public DragDropTestControl(object config) {
			if (!Script.IsUndefined(config)) {
				Dictionary __cfg = Dictionary.GetDictionary(config);
				this.id = (string)__cfg["id"];
				this.numItems = (int)__cfg["numItems"];
				Constructed();
				AttachSelf();
			}
			else {
				throw new Exception("This control must be created server-side");
			}
		}
	}
}
#endif
